package o2o.web.actions.user;

import com.alibaba.fastjson.JSON;
import com.mongodb.BasicDBObject;
import o2o.config.dao.MongoDaoImpl;
import o2o.task.user.UserLoginLogUtils;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

//登录日志管理

public class LoginLogMan {

    //新增日志
    public static void addLogin(String username) {
        addLogin(username,
                null, null,
                null, null,
                null, null, null, null);
    }


    public static void addLogin(String username,
                                Integer sysType, Integer deviceType,
                                Double lat, Double lng,
                                String province, String city, String county, String address) {


//        LoginLog loginLog = new LoginLog();
//        loginLog.setUsername(username);
//        loginLog.setSysType(sysType);
//        loginLog.setDeviceType(deviceType);
//        loginLog.setLat(lat);
//        loginLog.setLng(lng);
//        loginLog.setProvince(province);
//        loginLog.setCity(city);
//        loginLog.setCounty(county);
//        loginLog.setAddress(address);
//
//
//        Long time = DateUtils.getCurrTime();
//        loginLog.setDelFlag(0);
//        loginLog.setCreateTime(time);
//        loginLog.setCreateUser(username);
//
//        loginLog.setLoginTime(time);

//        try {
//            DataDaoSql.getInstance().insertObj(PojoTables.LOGIN_LOG, loginLog);
//        } catch (SQLException e) {
//            e.printStackTrace();
//            return;
//        }

//        // 更新mongoDB数据库
//        BasicDBObject query = new BasicDBObject();
//        query.append("username", username);
//
//        BasicDBObject update = new BasicDBObject();
//        update.append("username", username);
//        update.append("loginDate", System.currentTimeMillis());
//        update.append("loginDateStr", DateUtils.sdfDateTime.get().format(System.currentTimeMillis()));
//        MongoDaoImpl.getInstance().update("records_user", "user_login_curr", query, update, true);
//        MongoDaoImpl.getInstance().insert("records_user", "user_login", update);


        //-------v3
        UserLoginLogUtils.addLog(username);
    }

    public static void main(String[] args) {

//        String username = "18560126367";
//        BasicDBObject query = new BasicDBObject();
//        query.append("username", username);
//
//        BasicDBObject update = new BasicDBObject();
//        update.append("username", username);
//        update.append("loginDate", System.currentTimeMillis());
//        update.append("loginDateStr", DateUtils.sdfDateTime.get().format(System.currentTimeMillis()));
//        MongoDaoImpl.getInstance().update("records_user", "user_login_curr", query, update, true);

        String username = "18560126362";
        Set<String> uu = new HashSet<>();
        uu.add(username);
        uu.add("18560126363");
        uu.add("18560126364");
        BasicDBObject query = new BasicDBObject();
        query.append("username", new BasicDBObject("$in", uu));

        List<HashMap<String, Object>> lll = MongoDaoImpl.getInstance().find("records_user", "user_login_curr", query, 100);

        System.out.println(JSON.toJSON(lll));
    }


}
